package com.ruoyi.common.core.utils;


import com.alibaba.fastjson.JSON;
import org.jetbrains.annotations.NotNull;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * 说明：日期处理
 */
public class DateUtil {

	private final static SimpleDateFormat sdfYear = new SimpleDateFormat("yyyy");
	private final static SimpleDateFormat sdfDay = new SimpleDateFormat("yyyy-MM-dd");
	private final static SimpleDateFormat sdfDays = new SimpleDateFormat("yyyyMMdd");
	private final static SimpleDateFormat sdfTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	private final static SimpleDateFormat sdfTimes = new SimpleDateFormat("yyyyMMddHHmmss");

	/**
	 * 获取YYYY格式
	 * @return
	 */
	public static String getSdfTimes() {
		return sdfTimes.format(new Date());
	}

	/**
	 * 获取YYYY格式
	 * @return
	 */
	public static String getYear() {
		return sdfYear.format(new Date());
	}

	/**
	 * 获取YYYY-MM-DD格式
	 * @return
	 */
	public static String getDay() {
		return sdfDay.format(new Date());
	}

	/**
	 * 获取YYYYMMDD格式
	 * @return
	 */
	public static String getDays(){
		return sdfDays.format(new Date());
	}

	/**
	 * 获取YYYY-MM-DD HH:mm:ss格式
	 * @return
	 */
	public static String getTime() {
		return sdfTime.format(new Date());
	}

	/**
	* @Title: compareDate
	* @Description: TODO(日期比较，如果s>=e 返回true 否则返回false)
	* @param s
	* @param e
	* @return boolean
	* @throws
	* @author fh
	 */
	public static boolean compareDate(String s, String e) {
		if(fomatDate(s)==null||fomatDate(e)==null){
			return false;
		}
		return fomatDate(s).getTime() >=fomatDate(e).getTime();
	}

	/**
	 * 格式化日期
	 * @return
	 */
	public static Date fomatDate(String date) {
		DateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
		try {
			return fmt.parse(date);
		} catch (ParseException e) {
			e.printStackTrace();
			return null;
		}
	}


	/**
	 * 校验日期是否合法
	 * @return
	 */
	public static boolean isValidDate(String s) {
		DateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
		try {
			fmt.parse(s);
			return true;
		} catch (Exception e) {
			return false; // 如果throw java.text.ParseException或者NullPointerException，就说明格式不对
		}
	}

	/**
	 * @param startTime
	 * @param endTime
	 * @return
	 */
	public static int getDiffYear(Date startTime,Date endTime) {
		return (int) (((endTime.getTime()-startTime.getTime())/ (1000 * 60 * 60 * 24))/365);
	}

	/**
     * <li>功能描述：时间相减得到天数
     * @param beginDateStr
     * @param endDateStr
     * @return
     * long
     * @author Administrator
     */
    public static long getDaySub(String beginDateStr,String endDateStr){
        long day=0;
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Date beginDate = null;
        Date endDate = null;
            try {
				beginDate = format.parse(beginDateStr);
				endDate= format.parse(endDateStr);
			} catch (ParseException e) {
				e.printStackTrace();
			}
            day=(endDate.getTime()-beginDate.getTime())/(24*60*60*1000);
            //System.out.println("相隔的天数="+day);
        return day;
    }




	/**
	 * <li>功能描述：时间相减得到天数
	 * @return
	 * long
	 * @author Administrator
	 */
	public static long getDaySub(Date beginDate,Date endDate){

		return (endDate.getTime()-beginDate.getTime())/(24*60*60*1000);
	}
    /**
     * 得到n天之后的日期
     * @param days
     * @return
     */
    public static String getAfterDayDate(String days) {
    	int daysInt = Integer.parseInt(days);
        Calendar canlendar = Calendar.getInstance(); // java.util包
        canlendar.add(Calendar.DATE, daysInt); // 日期减 如果不够减会将月变动
        Date date = canlendar.getTime();
        SimpleDateFormat sdfd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String dateStr = sdfd.format(date);
        return dateStr;
    }

    /**
     * 得到n天之后是周几
     * @param days
     * @return
     */
    public static String getAfterDayWeek(String days) {
    	int daysInt = Integer.parseInt(days);
        Calendar canlendar = Calendar.getInstance(); // java.util包
        canlendar.add(Calendar.DATE, daysInt); // 日期减 如果不够减会将月变动
        Date date = canlendar.getTime();
        SimpleDateFormat sdf = new SimpleDateFormat("E");
        String dateStr = sdf.format(date);
        return dateStr;
    }

	/**
	 * 按照yyyy-MM-dd HH:mm:ss的格式，日期转字符串
	 * @param date
	 * @return yyyy-MM-dd HH:mm:ss
	 */
	public static String date2Str(Date date){
		if (Objects.isNull(date)){
			return null;
		}
		return date2Str(date,"yyyy-MM-dd HH:mm:ss");
	}

	public static String dateToDayStr(Date date){
		return date2Str(date,"yyyy-MM-dd");
	}

	/**
	 * 按照yyyy-MM-dd HH:mm:ss的格式，字符串转日期
	 * @param date
	 * @return
	 */
	public static Date str2Date(String date){
		if(!StringUtils.isEmpty(date)){
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			try {
				return sdf.parse(date);
			} catch (ParseException e) {
				e.printStackTrace();
			}
			return new Date();
		}else{
			return null;
		}
	}
	public static Date str2Date2(String date){
		if(!StringUtils.isEmpty(date)){
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
			try {
				return sdf.parse(sdf.format(date));
			} catch (ParseException e) {
				e.printStackTrace();
			}
			return new Date();
		}else{
			return null;
		}
	}

	public static Date str2DateTemp(String date){
		if(!StringUtils.isEmpty(date)){
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			try {
				return sdf.parse(date);
			} catch (ParseException e) {
				e.printStackTrace();
			}
			return new Date();
		}else{
			return null;
		}
	}

	/**
	 * 把时间根据时、分、秒转换为时间段
	 * @param StrDate
	 */
	public static String getTimes(String StrDate){
		String resultTimes = "";
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	    Date now;
	    try {
	    	now = new Date();
	    	Date date=df.parse(StrDate);
	    	long times = now.getTime()-date.getTime();
	    	long day  =  times/(24*60*60*1000);
	    	long hour = (times/(60*60*1000)-day*24);
	    	long min  = ((times/(60*1000))-day*24*60-hour*60);
	    	long sec  = (times/1000-day*24*60*60-hour*60*60-min*60);

	    	StringBuffer sb = new StringBuffer();
	    	//sb.append("发表于：");
	    	if(hour>0 ){
	    		sb.append(hour+"小时前");
	    	} else if(min>0){
	    		sb.append(min+"分钟前");
	    	} else{
	    		sb.append(sec+"秒前");
	    	}
	    	resultTimes = sb.toString();
	    } catch (ParseException e) {
	    	e.printStackTrace();
	    }
	    return resultTimes;
	}

	/**
	 * 按照参数format的格式，日期转字符串
	 * @param date
	 * @param format
	 * @return
	 */
	public static String date2Str(Date date,String format){
		if(date!=null){
			SimpleDateFormat sdf = new SimpleDateFormat(format);
			return sdf.format(date);
		}else{
			return "";
		}
	}

	/**
	 * 获取时间戳
	 * @param date
	 * @param format
	 * @return
	 */
	public static String toString(Date date, String format) {
		String dateStr = null;
		try {
			SimpleDateFormat sdf = new SimpleDateFormat(format);
			dateStr = sdf.format(date);
		} catch (Exception e) {
		}
		return dateStr;
	}

	/**
	 *
	 * @param termType 期限:1 天 2、月 3、年
	 * @param term
	 * @param signDate
	 * @return
	 */
	public static Date addDateByTerm(Integer termType, Integer term, Date signDate){
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(signDate);
		if (termType.equals(1)){
			calendar.add(Calendar.DAY_OF_MONTH,term);
		}else if(termType.equals(2)) {
			calendar.add(Calendar.MONTH,term);
		}else if (termType.equals(3)){
			calendar.add(Calendar.YEAR,term);
		}
		calendar.add(Calendar.DAY_OF_MONTH,-1);
		return calendar.getTime();
	}


	public static Date addYear(Integer year,Date startDate){
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(startDate);
		calendar.add(Calendar.YEAR,year);
		return calendar.getTime();
	}

	/**
	 * 查找当年当月的日期
	 * @param day
	 * @param startDate
	 * @return
	 */
	public static Date findFixedDay(Integer day,Date startDate){
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(startDate);
		Integer year =calendar.get(Calendar.YEAR);
		Integer month = calendar.get(Calendar.MONTH) +1;
		String time = year + "-" + (month < 10 ? "0" + month : month) + "-" +  (day < 10 ? "0" + day : day);
		return fomatDate(time);
	}

	/**
	 * 获取此日期在 n月之后的日期
	 * @param month
	 * @return
	 */
	public static String getDayByMonth(Date date,int month){
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		calendar.add(Calendar.MONTH, month);
		calendar.add(Calendar.DAY_OF_MONTH,-1);
		String time = new SimpleDateFormat("yyyy-MM-dd").format(calendar.getTime());
		return time;
	}

	/**
	 * 计算两个日期相差几个月
	 * @param startTime
	 * @param endTime
	 * @return
	 * @throws ParseException
	 */
	public static int getMonthSpace(String startTime, String endTime) throws ParseException {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		int result=0;
		Calendar cal1 = Calendar.getInstance();
		Calendar cal2 = Calendar.getInstance();
		cal1.setTime(sdf.parse(startTime));
		cal2.setTime(sdf.parse(endTime));
		result =(cal2.get(Calendar.YEAR) - cal1.get(Calendar.YEAR)) * 12 + cal2.get(Calendar.MONTH)- cal1.get(Calendar.MONTH);
		return result==0 ? 1 : Math.abs(result);
	}


	/**
	 * 计算两个日期间隔的月数
	 * @return int
	 * @throws ParseException
	 */
	public static int getMonthSpaceTemp(String startTime, String endTime) throws ParseException {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		int result = 0;

		Calendar c1 = Calendar.getInstance();
		Calendar c2 = Calendar.getInstance();

		c1.setTime(sdf.parse(startTime));
		c2.setTime(sdf.parse(endTime));

		int year1 = c1.get(Calendar.YEAR);
		int year2 = c2.get(Calendar.YEAR);

		result = (year2 * 12 + c2.get(Calendar.MONDAY)) - (year1 * 12 + c1.get(Calendar.MONDAY));
		return Math.abs(result);
	}

	/**
	 * 获取此日期在 n天之后的日期
	 * @param day
	 * @return
	 */
	public static String addDay(String time, int day) throws ParseException {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Date date = sdf.parse(time);
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		calendar.add(Calendar.DATE, day);
		return new SimpleDateFormat("yyyy-MM-dd").format(calendar.getTime());
	}


	public static Date addDay(Date time, int day) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(time);
		calendar.add(Calendar.DATE, day);
		return calendar.getTime();
	}

	public static Date addMonth(Date time, int month) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(time);
		calendar.add(Calendar.MONTH, month);
		return calendar.getTime();
	}

	/**
	 * 设置固定时间  20号
	 * @param time
	 * @return
	 * @throws ParseException
	 */
	public static String getFixedDate(String time) throws ParseException {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Date date = sdf.parse(time);
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		int year = calendar.get(Calendar.YEAR);
		int month = calendar.get(Calendar.MONTH) + 1;
		int day = calendar.get(Calendar.DAY_OF_MONTH);

		if(day < 20){  //小于20时 取次月20号
			month = month+1;
			String m = month > 9 ? month+"" : "0"+month;
			return year+"-"+m+"-20";
		}else if(month < 12){
			month = month+1;
			String m = month > 9 ? month+"" : "0"+month;
			return year+"-"+m+"-20";
		}else{
			return (year+1)+"-01-20";
		}
	}

	/**
	 * 获取当月 20号
	 * @param time
	 * @return
	 * @throws ParseException
	 */
	public static String getCurrentDate(String time) throws ParseException {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Date date = sdf.parse(time);
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		int year = calendar.get(Calendar.YEAR);
		int month = calendar.get(Calendar.MONTH)+1;
		int day = calendar.get(Calendar.DAY_OF_MONTH);

		return year+"-"+month+"-20";
	}

	/**
	 * 获取次月20号时间
	 * @param time
	 * @return
	 * @throws ParseException
	 */
	public static String getNextFixedDate(String time) throws ParseException {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Date date = sdf.parse(time);
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		int year = calendar.get(Calendar.YEAR);
		int month = calendar.get(Calendar.MONTH) + 2;
		int day = calendar.get(Calendar.DAY_OF_MONTH);
		System.err.println("year"+year);
		System.err.println("month"+month);
		System.err.println("day"+day);
		if(day < 20){
			String m = month > 9 ? month+"" : "0"+month;
			if (month > 12){
				return (year+1)+"-01-20";
			}
			return year+"-"+m+"-20";
		} else if(month < 12){
			month = month+1;
			String m = month > 9 ? month+"" : "0"+month;
			return year+"-"+m+"-20";
		}else{
			return (year+1)+"-01-20";
		}
	}

	/**
	 * 时间大小
	 * @param startTime
	 * @param endTime
	 * @return
	 * @throws ParseException
	 */
	public static String dateSize(String startTime,String endTime) throws ParseException {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Date date1 = sdf.parse(startTime);
		Date date2 = sdf.parse(endTime);
		if(date1.getTime() < date2.getTime()){ //开始时间小于结束时间
			return "xy";
		}else if(date1.getTime() > date2.getTime()){ //开始时间大于结束时间
			return "dy";
		}else { //时间相同
			return "xt";
		}
	}

	/**
	 * 获取日期号数
	 * @param time
	 * @return
	 * @throws ParseException
	 */
	public static int getDayNum(String time) throws ParseException {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Date date = sdf.parse(time);
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		int day = calendar.get(Calendar.DAY_OF_MONTH);
		return day;
	}

	/**
	 * 获取季度日期
	 * @param time
	 * @return
	 *          3-20
	 *          6-20
	 *          9-20
	 *          12-20
	 */
	public static String getQuarterDate(String time) throws ParseException {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Date date = sdf.parse(time);
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		int year = calendar.get(Calendar.YEAR);
		int month = calendar.get(Calendar.MONTH) + 1;
		int day = calendar.get(Calendar.DAY_OF_MONTH);
		String timeStr = "";

		if(month % 3 == 0){ //说明日期在季度月（3，6，9，12）
			if (day < 20){
				String m = month > 9 ? month+"" : "0"+month;
				timeStr = year+"-"+m+"-20";
			}else {
				month = month + 3;
				if(month > 12){
					month = 3;
					year = year + 1;
				}
				String m = month > 9 ? month+"" : "0"+month;
				timeStr = year+"-"+m+"-20";
			}
		}else{ //不在季度月
			for (int i=0; i< 3; i++){
				month = month + 1;
				if(month % 3 == 0) {
					String m = month > 9 ? month + "" : "0" + month;
					timeStr = year + "-" + m + "-20";
					break;
				}
			}
		}

		return timeStr;
	}

	/**
	 * 获取季度期数
	 * @param StartTime
	 * @return
	 */
	public static int getQuarterNum(String StartTime,String endTime) throws ParseException {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Date date = sdf.parse(StartTime);
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		int day = calendar.get(Calendar.DAY_OF_MONTH);
		System.err.println(day);
		int num = 1;

//		int month = DateUtil.getMonthSpace(StartTime , endTime);  //获取两个日期相差的月数
		int month = getMonthSpaceTemp(StartTime, endTime);
//		month = 25;
		System.err.println(month);
		if(month < 3){ //小于三个月,返回一期
			return 1;
		}
		if(month % 3 == 0){ //说明日期在季度月（3，6，9，12）
			if (day != 20){
				num = (month / 3)+1;
			}else {
				num = (month / 3)+1;
			}
		}else{ //不在季度月
			if (day != 20){
				num = (month / 3)+2;
			}else {
				num = (month / 3)+1;
			}
		}
		return num;
	}

	/**
	 * 当前季度的开始时间
	 *
	 * @return
	 */
	public static Date getQuarterStartTimeByYear(Integer year,int quarter) {
		Calendar c = Calendar.getInstance();
		c.set(Calendar.YEAR,year);
		if (quarter == 1) {
			c.set(Calendar.MONTH, 0);
		} else if (quarter == 2) {
			c.set(Calendar.MONTH, 3);
		} else if (quarter == 3) {
			c.set(Calendar.MONTH, 4);
		} else if (quarter == 4) {
			c.set(Calendar.MONTH, 9);
		}
		c.set(Calendar.DATE, 1);
		return c.getTime();
	}

	/**
	 * 当前季度的结束时间:如果结束时间大于当前时间，则放回当前时间
	 *
	 * @return
	 */
	public static Date getQuarterEndTimeByYear(Integer year,int quarter) {
		Calendar c = Calendar.getInstance();
		c.set(Calendar.YEAR,year);
		if (quarter == 1) {
			c.set(Calendar.MONTH, 2);
			c.set(Calendar.DATE, 31);
		} else if (quarter == 2) {
			c.set(Calendar.MONTH, 5);
			c.set(Calendar.DATE, 30);
		} else if (quarter == 3) {
			c.set(Calendar.MONTH, 8);
			c.set(Calendar.DATE, 30);
		} else if (quarter == 4) {
			c.set(Calendar.MONTH, 11);
			c.set(Calendar.DATE, 31);
		}
		Date quarterDate = c.getTime();
		Date now = new Date();
		if (now.compareTo(quarterDate) <0){
			return now;
		}
		return quarterDate;
	}

	/**
	 * 按照yyyy-MM-dd HH:mm:ss的格式，日期转字符串
	 * @param date
	 * @return yyyy-MM-dd HH:mm:ss
	 */
	public static String date3Str(Date date){
		return date2Str(date,"yyyy-MM-dd");
	}

	/**
	 * 按照yyyy-MM-dd的格式，字符串转日期
	 * @param date
	 * @return
	 */
	public static Date str3Date(String date){
		if(!StringUtils.isEmpty(date)){
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			try {
				return sdf.parse(date);
			} catch (ParseException e) {
				e.printStackTrace();
			}
			return new Date();
		}else{
			return null;
		}
	}

	public static int getDateDay(Date date){
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		int day = calendar.get(Calendar.DATE);
		return day;
	}

	public static void main(String[] args) {

//		System.err.println(formatNYRStr("2010-01-10"));
//		System.err.println(formatNYRStr("2021-01-01"));
//		System.err.println(formatNYRStr("2010-1-28"));
//		System.err.println(formatNYRStr("2010-11-20"));
//		System.err.println(formatNYRStr("2010-12-31"));
//		long daySub2 = getDaySub("2018-10-15", "2018-10-20");
//		long daySub3 = getDaySub("2018-09-21", "2018-10-20");
//		System.err.println(daySub1+1);
//		System.err.println(daySub2);
//		System.err.println(daySub3);

	/*	String time = getTime();
		time = time.substring(10,time.length());*/

	}


	/**
	 * 2010-01-10 转换成 2010年01月10日
	 * @return
	 */
	public static String getStrNYR(String dateStr) {
		Date date = null;
		try {
			date = new SimpleDateFormat("yyyy-MM-dd").parse(dateStr);
		} catch (ParseException e) {

		}
		String now = new SimpleDateFormat("yyyy年MM月dd日").format(date);
		return now;
	}

	public static Boolean isSameMonth(Date curStartMonth, Date dayTime) {
		Calendar startCalendar = Calendar.getInstance();
		startCalendar.setTime(curStartMonth);

		Calendar endCalendar = Calendar.getInstance();
		endCalendar.setTime(dayTime);

		int startYear = startCalendar.get(Calendar.YEAR);
		int startMonth = startCalendar.get(Calendar.MONTH) + 1;

		int endYear = endCalendar.get(Calendar.YEAR);
		int endMonth = endCalendar.get(Calendar.MONTH) + 1;
		//年月相等
		if (startYear == endYear && startMonth == endMonth){
			return Boolean.TRUE;
		}
		return Boolean.FALSE;
	}


	/**
	 * create date:2010-5-22下午03:32:46
	 * 描述：格式化日期
	 * @param str 源字符串中的字符
	 * @return
	 */
	public static String formatNYRStr(String str){
		StringBuffer sb = new StringBuffer();
		int pos1 = str.indexOf("-");
		int pos2 = str.lastIndexOf("-");
		for(int i = 0; i < 4; i++){
			sb.append(formatDigit(str.charAt(i)));
		}
		sb.append('年');
		if(getMidLen(str,pos1,pos2) == 1){
			sb.append(formatDigit(str.charAt(5))+"月");
			if(str.charAt(7) != '0'){
				if(getLastLen(str, pos2) == 1){
					sb.append(formatDigit(str.charAt(7))+"日");
				}
				if(getLastLen(str, pos2) == 2){
					if(str.charAt(7) != '1' && str.charAt(8) != '0'){
						sb.append(formatDigit(str.charAt(7))+"十"+formatDigit(str.charAt(8))+"日");
					}
					else if(str.charAt(7) != '1' && str.charAt(8) == '0'){
						sb.append(formatDigit(str.charAt(7))+"十日");
					}
					else if(str.charAt(7) == '1' && str.charAt(8) != '0'){
						sb.append("十"+formatDigit(str.charAt(8))+"日");
					}
					else{
						sb.append("十日");
					}
				}
			}
			else{
				sb.append(formatDigit(str.charAt(8))+"日");
			}
		}
		if(getMidLen(str,pos1,pos2) == 2){
			if(str.charAt(5) != '0' && str.charAt(6) != '0'){
				sb.append("十"+formatDigit(str.charAt(6))+"月");
				if(getLastLen(str, pos2) == 1){
					sb.append(formatDigit(str.charAt(8))+"日");
				}
				if(getLastLen(str, pos2) == 2){
					if(str.charAt(8) != '0'){
						if(str.charAt(8) != '1' && str.charAt(9) != '0'){
							sb.append(formatDigit(str.charAt(8))+"十"+formatDigit(str.charAt(9))+"日");
						}
						else if(str.charAt(8) != '1' && str.charAt(9) == '0'){
							sb.append(formatDigit(str.charAt(8))+"十日");
						}
						else if(str.charAt(8) == '1' && str.charAt(9) != '0'){
							sb.append("十"+formatDigit(str.charAt(9))+"日");
						}
						else{
							sb.append("十日");
						}
					}
					else{
						sb.append(formatDigit(str.charAt(9))+"日");
					}
				}
			}
			else if(str.charAt(5) != '0' && str.charAt(6) == '0'){
				sb.append("十月");
				if(getLastLen(str, pos2) == 1){
					sb.append(formatDigit(str.charAt(8))+"日");
				}
				if(getLastLen(str, pos2) == 2){
					if(str.charAt(8) != '0'){
						if(str.charAt(8) != '1' && str.charAt(9) != '0'){
							sb.append(formatDigit(str.charAt(8))+"十"+formatDigit(str.charAt(9))+"日");
						}
						else if(str.charAt(8) != '1' && str.charAt(9) == '0'){
							sb.append(formatDigit(str.charAt(8))+"十日");
						}
						else if(str.charAt(8) == '1' && str.charAt(9) != '0'){
							sb.append("十"+formatDigit(str.charAt(9))+"日");
						}
						else{
							sb.append("十日");
						}
					}
					else{
						sb.append(formatDigit(str.charAt(9))+"日");
					}
				}
			}
			else{
				sb.append(formatDigit(str.charAt(6))+"月");
				if(getLastLen(str, pos2) == 1){
					sb.append(formatDigit(str.charAt(8))+"日");
				}
				if(getLastLen(str, pos2) == 2){
					if(str.charAt(8) != '0'){
						if(str.charAt(8) != '1' && str.charAt(9) != '0'){
							sb.append(formatDigit(str.charAt(8))+"十"+formatDigit(str.charAt(9))+"日");
						}
						else if(str.charAt(8) != '1' && str.charAt(9) == '0'){
							sb.append(formatDigit(str.charAt(8))+"十日");
						}
						else if(str.charAt(8) == '1' && str.charAt(9) != '0'){
							sb.append("十"+formatDigit(str.charAt(9))+"日");
						}
						else{
							sb.append("十日");
						}
					}
					else{
						sb.append(formatDigit(str.charAt(9))+"日");
					}
				}
			}
		}
		return sb.toString();
	}
	/**
	 * create date:2010-5-22下午03:32:31
	 * 描述：将源字符串中的阿拉伯数字格式化为汉字
	 * @param sign 源字符串中的字符
	 * @return
	 */
	public static char formatDigit(char sign){
		if(sign == '0')
			sign = '零';
		if(sign == '1')
			sign = '一';
		if(sign == '2')
			sign = '二';
		if(sign == '3')
			sign = '三';
		if(sign == '4')
			sign = '四';
		if(sign == '5')
			sign = '五';
		if(sign == '6')
			sign = '六';
		if(sign == '7')
			sign = '七';
		if(sign == '8')
			sign = '八';
		if(sign == '9')
			sign = '九';
		return sign;
	}

	/**
	 * create date:2010-5-22下午03:32:17
	 * 描述：获得日期字符串的长度
	 * @param str  待转换的源字符串
	 * @param pos2 第二个'-'的位置
	 * @return
	 */
	public static int getLastLen(String str,int pos2){
		return str.substring(pos2+1).length();
	}

	/**
	 * create date:2010-5-22下午03:31:51
	 * 描述： 获得月份字符串的长度
	 * @param str  待转换的源字符串
	 * @param pos1 第一个'-'的位置
	 * @param pos2 第二个'-'的位置
	 * @return
	 */
	public static int getMidLen(String str,int pos1,int pos2){
		return str.substring(pos1+1, pos2).length();
	}



}
